package com.ruoyi.basic.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.basic.domain.BdCoderule;
import com.ruoyi.basic.service.IBdCoderuleService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 编码规则Controller
 * 
 * @author ruoyi
 * @date 2021-01-29
 */
@RestController
@RequestMapping("/coderule")
public class BdCoderuleController extends BaseController
{
    @Autowired
    private IBdCoderuleService bdCoderuleService;

    /**
     * 查询编码规则列表
     */
    @PreAuthorize(hasPermi = "system:coderule:list")
    @GetMapping("/list")
    public TableDataInfo list(BdCoderule bdCoderule)
    {
        startPage();
        List<BdCoderule> list = bdCoderuleService.selectBdCoderuleList(bdCoderule);
        return getDataTable(list);
    }

    /**
     * 导出编码规则列表
     */
    @PreAuthorize(hasPermi = "system:coderule:export")
    @Log(title = "编码规则", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BdCoderule bdCoderule) throws IOException
    {
        List<BdCoderule> list = bdCoderuleService.selectBdCoderuleList(bdCoderule);
        ExcelUtil<BdCoderule> util = new ExcelUtil<BdCoderule>(BdCoderule.class);
        util.exportExcel(response, list, "coderule");
    }

    /**
     * 获取编码规则详细信息
     */
    @PreAuthorize(hasPermi = "system:coderule:query")
    @GetMapping(value = "/{bdCrcode}")
    public AjaxResult getInfo(@PathVariable("bdCrcode") String bdCrcode)
    {
        return AjaxResult.success(bdCoderuleService.selectBdCoderuleById(bdCrcode));
    }

    /**
     * 新增编码规则
     */
    @PreAuthorize(hasPermi = "system:coderule:add")
    @Log(title = "编码规则", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BdCoderule bdCoderule)
    {
        return toAjax(bdCoderuleService.insertBdCoderule(bdCoderule));
    }

    /**
     * 修改编码规则
     */
    @PreAuthorize(hasPermi = "system:coderule:edit")
    @Log(title = "编码规则", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BdCoderule bdCoderule)
    {
        return toAjax(bdCoderuleService.updateBdCoderule(bdCoderule));
    }

    /**
     * 删除编码规则
     */
    @PreAuthorize(hasPermi = "system:coderule:remove")
    @Log(title = "编码规则", businessType = BusinessType.DELETE)
	@DeleteMapping("/{bdCrcodes}")
    public AjaxResult remove(@PathVariable String[] bdCrcodes)
    {
        return toAjax(bdCoderuleService.deleteBdCoderuleByIds(bdCrcodes));
    }
}
